package com.example.myapplicatio

import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageView
import android.widget.SeekBar
import android.widget.Toast
import androidx.annotation.RequiresApi

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val seekBar = findViewById<SeekBar>(R.id.seek_bar1)
        val imageView = findViewById<ImageView>(R.id.image1)

        seekBar.setOnSeekBarChangeListener(object:SeekBar.OnSeekBarChangeListener{
            @RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
            override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {
                //设置图片透明度
                imageView.imageAlpha = p1
            }

            //开始触摸
            override fun onStartTrackingTouch(p0: SeekBar?) {
                Toast.makeText(this@MainActivity,"开始触摸",Toast.LENGTH_SHORT).show()
            }

            //停止触摸
            override fun onStopTrackingTouch(p0: SeekBar?) {
                Toast.makeText(this@MainActivity,"停止触摸",Toast.LENGTH_SHORT).show()
            }
        })

    }
}
